﻿ 
var pi = 1;
var dateType = 1;
$(function () {
    get_list(1);

    $('.switch_tab li').click(function () {
        $('.switch_tab li').removeClass("current");
        $(this).addClass('current');


        dateType = $(this).attr('data-type');
        get_list(1);
    })
})

function get_list(ty) {
    //alert(1);
    if (ty == 1) {
        $('#table_list').html("");
        pi = 1;
    }
    else { }

    $.ajax({
        type: "post",
        url: "/agentcenter/GetEffect?pi=" + pi,
        data: {
            pi: pi,
            dateType: dateType

        },
        dataType: "json",
        success: function (data) {
            if (data.State) {
                var list = data.Datas;
                var content = "";
                for (var i = 0; i < list.length; i++) {
                    content += " <tr> ";
                    content += "<td>" + list[i].DateTime + "</td>";
                    content += "<td>" + list[i].Type + "</td>";
                    content += "<td>" + list[i].ClickNum + "</td>";
                    content += "<td>" + list[i].PayNum + "</td>";
                    content += "<td>" + list[i].Estimate + "</td>";
                    content += "<td>" + list[i].Income + "</td>";

                    content += "</tr>";



                }
                $('#table_list').append(content);
                pi++;
            }

        },
        error: function (data) {

        }

    })




}
function formatDate(nS) {
    return new Date(parseInt(nS)).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}

//==============自动加载=============
//获取滚动条当前的位置
function getScrollTop() {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

//获取当前可是范围的高度
function getClientHeight() {
    var clientHeight = 0;
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
    }
    else {
        clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
    }
    return clientHeight;
}

//获取文档完整的高度
function getScrollHeight() {
    return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}


$(window).scroll(function () {
    if (getScrollTop() + getClientHeight() == getScrollHeight()) {
        //alert("到达底部");
        get_list(0);
    }
});

//==============自动加载=============
